package st.business.tepth.business.user.busnumber;

import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.view.ViewGroup;

import java.util.List;

import st.business.tepth.business.bean.BusNumberBean;
import st.business.tepth.business.user.busnumber.finishholder.maintain.FinishMaintainDelegate;
import st.business.tepth.business.user.busnumber.finishholder.repair.FinishRepairDelegate;
import st.business.tepth.business.user.busnumber.preholder.repair.PreRepairDelegate;
import st.business.tepth.business.user.busnumber.workholder.maintain.MaintainWorkHolderDelegate;
import st.business.tepth.business.user.busnumber.workholder.repair.RepairWorkHolderDelegate;

/**
 * @author zhangyu
 * @date 2019/1/17
 */
public class BusNumberAdapter extends FragmentStatePagerAdapter {

    private List<BusNumberBean> mList;

    private BusNumberAdapter(FragmentManager fm) {
        super(fm);
    }

    public BusNumberAdapter(FragmentManager fm, List<BusNumberBean> list) {
        this(fm);
        mList = list;
    }

    @Override
    public Fragment getItem(int position) {
        BusNumberBean busNumberBean = mList.get(position);
        if (busNumberBean != null) {
            int type = busNumberBean.getType();
            int jobStatus = busNumberBean.getJob_process_status();
            if (type == 1) {
                //小修
                switch (jobStatus) {
                    case 1:
                        //待作业
                        return PreRepairDelegate.newInstance(
                                mList.get(position).getId());
                    case 2:
                        //作业中
                        return RepairWorkHolderDelegate.newInstance(
                                mList.get(position).getId());
                    case 3:
                        //已完成
                        return FinishRepairDelegate.newInstance(
                                mList.get(position).getId());
                }
            } else {
                //保养
                switch (jobStatus) {
                    case 1:
                        //待作业
                        return FinishMaintainDelegate.newInstance(busNumberBean, false);
                    case 2:
                        //作业中
                        return MaintainWorkHolderDelegate.newInstance(
                                mList.get(position).getId());
                    case 3:
                        //已完成
                        return FinishMaintainDelegate.newInstance(busNumberBean, true);
                }
            }
        }
        return null;
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        return super.instantiateItem(container,
                position);
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position,
                            @NonNull Object object) {
        // TODO Auto-generated method stub
        super.destroyItem(container, position, object);

    }

    @Override
    public CharSequence getPageTitle(int position) {
        return position + "号工位";
    }

    @Override
    public int getItemPosition(@NonNull Object object) {
        return POSITION_NONE;
    }

}
